package com.guigu.xiaowenbo.controller;

import com.guigu.aop.OpLog;
import com.guigu.liuzhireng.pojo.Account;
import com.guigu.util.PageVo;
import com.guigu.util.service.IDService;
import com.guigu.xiaowenbo.pojo.Scell;
import com.guigu.xiaowenbo.service.DfilerService;
import com.guigu.xiaowenbo.service.ScellService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpSession;

@Controller
public class ScellController {
    @Autowired
    ScellService scellService;
    @Autowired
    DfilerService dfilerService;
    @Autowired
    IDService idService;

    @PostMapping("insert")
    @ResponseBody
    @OpLog(opModule = "安全库存配置管理",operType = "制定安全库存",operDesc = "此方法用于制定安全库存")
    public int insert(@RequestBody Scell scell){
        System.out.println(1);
        String storeid = idService.Repertory_ID();
            scell.setStoreid(storeid);
            scellService.insert(scell);
            dfilerService.udtpr(scell.getId());
            return 1;
    }
    @RequestMapping("selsc")
    @ResponseBody
    public PageVo selsc(@RequestBody PageVo<Scell> scell){
        return  scellService.selectByPrimaryKeyfh(scell.getNum(),scell.getSize());
    }

    @RequestMapping("selectByPrimaryKeyfhid")
    public ModelAndView selectByPrimaryKeyfhid(String storeid, HttpSession session){
        String acc = ((Account) session.getAttribute("user")).getAccount();
        ModelAndView modelAndView = new ModelAndView();
        Scell scell = scellService.selectByPrimaryKeyfhid(storeid);
        modelAndView.addObject("scell",scell);
        modelAndView.addObject("name",acc);
        modelAndView.setViewName("xiao_wen_bo/demofh.jsp");
        return modelAndView;
    }
    @RequestMapping("selectByPrimaryKeyfhbgid")
    public ModelAndView selectByPrimaryKeyfhbgid(String storeid, HttpSession session){
        String acc = ((Account) session.getAttribute("user")).getAccount();
        ModelAndView modelAndView = new ModelAndView();
        Scell scell = scellService.selectByPrimaryKeyfhid(storeid);
        modelAndView.addObject("scell",scell);
        modelAndView.addObject("name",acc);
        modelAndView.setViewName("xiao_wen_bo/demofhbg.jsp");
        return modelAndView;
    }
    @RequestMapping("updateByPrimaryKeySelective")
    @OpLog(opModule = "安全库存配置管理",operType = "审核制定安全库存",operDesc = "此方法用于审核制定安全库存")
    public String updateByPrimaryKeySelective(Scell scell){
        scellService.updateByPrimaryKeySelective(scell);
        return "xiao_wen_bo/aqkucunfh.jsp";
    }
    @RequestMapping("selectByPrimaryKeyfhcx")
    @ResponseBody
    public PageVo selectByPrimaryKeyfhcx(@RequestBody PageVo<Scell> scell){
        return scellService.selectByPrimaryKeyfhcx(scell.getNum(),scell.getSize());
    }
    @RequestMapping("updateByPrimaryKeySelectivebg")
    @OpLog(opModule = "安全库存配置管理",operType = "变更制定安全库存",operDesc = "此方法用于变更制定安全库存")
    public String updateByPrimaryKeySelectivebg(Scell scell){
        scellService.updateByPrimaryKeySelectivebg(scell);
        return "xiao_wen_bo/aqkucunfh.jsp";
    }
    @RequestMapping("selectpid")
    public Scell selectpid(String prouctid){
        return scellService.selectpid(prouctid);

    }
}
